<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <include file="./Public/Admin/header.html" />
    <style>
        /*#loading {width:100%;height:100%;display:none;position:fixed;top:0px;left:0px;background:url('data/images/load.gif') no-repeat center; background-size:2%;background-color:rgba(0, 0, 0, 0.75);z-index:10000000;}*/
    </style>
</head>
<body>
<body>
<div id="main">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="span12">
                <div class="box">
                    <div class="box-title">
                        <div class="span4">
                            <h3><i class="icon-table"></i>粉丝管理</h3>
                        </div>
                        <div class="btn-group pull-right clearfix ">
                            <form action="{:U('Admin/Wechat/wxusers')}" method="get" class="form-horizontal" style="margin: 0px;">
                                <input type="text" id="keyword" name="keyword" value="{$keyword}" class="input-small-z" placeholder="请输入关键词" data-rule-required="true" />

                                <button class="btn" id="btn_search">查询</button>
                            </form>
                        </div>
                    </div>
                    <div class="box-content">
                        <div class="alert hide">
                            <span class="member-count">会员总数: 0</span><span>今日新增: 0</span>
                        </div>
                        <div class="row-fluid">
                            <div class="span12 control-group">
                                <div class="span4">
                                    <button class="btn" title="批量加入分组" id='btnaddg'><i class="icon-plus"></i>批量加入群组</button>
                                    <a class="btn" href="javascript:location.reload()"><i class="icon-refresh"></i>刷新</a>
                                </div>
                            </div>

                        </div>

                        <div class="row-fluid dataTables_wrapper">
                            <table id="listTable" class="table table-bordered table-hover  dataTable">
                                <thead>
                                <tr>
                                    <th class='with-checkbox'>
                                        <input type="checkbox" class="check_all" /></th>
                                    <th>头像</th>
                                    <th>昵称</th>
                                    <th>性别</th>
                                    <th>地址</th>
                                    <th>关注时间</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                <foreach name="users" item="item">
                                    <tr>
                                        <td class="with-checkbox">
                                            <input type="checkbox" name="check" value="{$item.openid}">
                                        </td>
                                        <td style="text-align:left;">
                                            <if condition="$item.headimgurl!=''">
                                                <p><img src="{$item.headimgurl}" style="max-width:60px;max-height:60px; "></p>
                                            </if>
                                        </td>
                                        <td>{$item.nickname}</td>
                                        <td>
                                            <if condition="$item.sex == 1">
                                                男
                                            <elseif condition="$item.sex == 2"/>
                                                女
                                            <else/>
                                                未知
                                            </if>
                                        </td>
                                        <td>{$item.country}{$item.province}{$item.city}</td>
                                        <td>{$item.subscribe_time|date="Y-m-d H:i:s",###}</td>
                                        <td class='hidden-480'>
                                            <a href="javascript:void(0);" class="btn" rel="tooltip" title="加入群组" attr="add*text*{$item.id}"><i class="icon-plus"></i>加入群组</a>
                                        </td>
                                    </tr>
                                </foreach>
                                <if condition="$total==0">
                                    <tr><td align="center" colspan="10">暂无记录</td></tr>
                                </if>

                                </tbody>
                            </table>
                            <div class="row-fluid">
                                <div class="span4">
                                    <div class="dataTables_info">
                                        <if condition="$total gt 0">
                                            共{$total}条记录，当前第{$nowPage}/{$totalPages}页
                                        </if>
                                    </div>
                                </div>
                                <div class="span8">
                                    <div class="dataTables_paginate paging_full_numbers">
                                        <span>
                                            {$page}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<script type="text/javascript">
    $(function(){
        $("#btn_search").click(function(){
            var keywords = $.trim($('#keyword').val());
            if (keywords.length <= 0) {
                //alert('请输入搜索关键字.');
                //$('#keyword').focus();
                //return false;
            }
            //window.location.href = '/wechat/replytext/aid/'+$('#aid').val()+'/type/'+$('#select_type').val()+'/keywords/' + keywords;
        });
        $("#keyword").keyup(function(e) {
            if (e.keyCode == 13) {
                $("#btn_search").click();
                return false;
            }
        });

        var openids=new Array();

        $("#btnaddg").click(function() {
            var check = $("input:checked").not($(".check_all")[0]);
            if(check.length<1){
                alert('请选择用户');
                return false;
            }
            check.each(function(i){
                openids[i] = $(this).val();
            });
            $('#myModal').modal('show');
        });

        $("a[attr^='add*text*']").click(function(){
            var tmp = $(this).attr('attr').split('*');
            openids[0]=tmp[2];
            $('#myModal').modal('show');

        });

        $("#btn_state_save").live('click',function(){
            var group=$("#groups").val();
            if(group==""){
                alert("请选择分组");
                return;
            }
            $.post("{:U('Admin/Wechat/set_user_group')}",{openids:openids,group_id:group},function(data){
                $("#loading").hide();
                if (data.errno ==0)
                {
                    G.ui.tips.err(data.error);
                    //location.reload();
                } else{
                    G.ui.tips.err(data.error);
                }
            },'json');
            $('#myModal').modal('hide');
            //显示正在加载
            $("#loading").show();
        });
    });
</script>
<div id="myModal" style="width: 300px;" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">加入群组</h3>
    </div>
    <div class="modal-body">
        <select id="groups">
            <option value="">--请选择分组--</option>
            <foreach name="groups" item="item">
            <option value="{$item.id}">{$item.groupname}</option>
            </foreach>
        </select>
        <input type="hidden" id="useropenid"/>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
        <button class="btn btn-primary" id="btn_state_save">保存</button>
    </div>
</div>
<div id="loading"></div>
</body>
</html>
